<template>
    <div class="page-header-index-wide">
        <div class="table-page-search-wrapper">
            <a-form layout="inline">
                <a-row :gutter="24">
                    <a-col :span="14">
                        <a-form-item label="根据时间进行查询">
                            <j-date placeholder="请选择开始时间" class="query-group-cust"
                                v-model="queryParam.startTime"></j-date>
                            <span class="query-group-split-cust"></span>
                            <j-date placeholder="请选择结束日期" class="query-group-cust"
                                v-model="queryParam.endTime"></j-date>
                        </a-form-item>
                    </a-col>
                    <a-col :span="10">
                        <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
                    </a-col>
                </a-row>
            </a-form>
        </div>
        <a-row :gutter="24" :style="{ marginTop: '16px' }">
            <a-col :span="8">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>合格记录总数(条)</span>
                        <el-tooltip class="item" effect="dark" placement="top">
                            <div slot="content">合格记录总数(条)
                                <hr />
                                合格车辆数 : 每个车牌号只出现一次的合格记录总数<br>
                                对车牌号进行去重处理
                            </div>
                            <el-button icon="el-icon-more" circle
                                style="float: right; padding: 5px 5px"></el-button>
                        </el-tooltip>
                    </div>
                    <div class="text item" style="font-size: 44px;">{{qualifiedTotal.total}}</div>
                    <div class="text item">合格车辆数 {{qualifiedTotal.totalUnique}}</div>
                </el-card>
            </a-col>
            <a-col :span="8">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>驳回记录总数(条)</span>
                        <el-tooltip class="item" effect="dark" placement="top">
                            <div slot="content">驳回记录总数(条)
                                <hr />
                                驳回车辆数 : 每个车牌号只出现一次的驳回记录总数<br>
                                对车牌号进行去重处理
                            </div>
                            <el-button icon="el-icon-more" circle
                                style="float: right; padding: 5px 5px"></el-button>
                        </el-tooltip>
                    </div>
                    <div class="text item" style="font-size: 44px;">{{noPassTotal.noPassTotal}}
                    </div>
                    <div class="text item">驳回车辆数 {{noPassTotal.noPassUnique}}</div>
                </el-card>
            </a-col>
            <a-col :span="8">
                <el-card class="box-card">
                    <div slot="header" class="clearfix">
                        <span>验罐不合格记录总数(条)</span>
                        <el-tooltip class="item" effect="dark" placement="top">
                            <div slot="content">验罐不合格记录总数(条)
                                <hr />
                                验罐不合格车辆数 : 每个车牌号只出现一次的验罐不合格记录总数<br>
                                对车牌号进行去重处理
                            </div>
                            <el-button icon="el-icon-more" circle
                                style="float: right; padding: 5px 5px"></el-button>
                        </el-tooltip>
                    </div>
                    <div class="text item" style="font-size: 44px;">
                        {{unqualifiedTotal.unqualifiedTotal}}</div>
                    <div class="text item">验罐不合格车辆数 {{unqualifiedTotal.unqualifiedUnique}}</div>
                </el-card>
            </a-col>
        </a-row>

        <a-row>
            <a-col :span="24">
                <a-card :loading="loading" :bordered="false" title="流程图"
                    :style="{ marginTop: '24px' }">
                    <img src="~@/assets/process.png" class="logo" alt="logo" width="100%" />
                    <!-- <a-row>
                        <a-col :span="6">
                            <head-info title="今日IP" :content="loginfo.todayIp"></head-info>
                        </a-col>
                        <a-col :span="2">
                            <a-spin class="circle-cust">
                                <a-icon slot="indicator" type="environment"
                                    style="font-size: 24px" />
                            </a-spin>
                        </a-col>
                        <a-col :span="6">
                            <head-info title="今日访问" :content="loginfo.todayVisitCount"></head-info>
                        </a-col>
                        <a-col :span="2">
                            <a-spin class="circle-cust">
                                <a-icon slot="indicator" type="team" style="font-size: 24px" />
                            </a-spin>
                        </a-col>
                        <a-col :span="6">
                            <head-info title="总访问量" :content="loginfo.totalVisitCount"></head-info>
                        </a-col>
                        <a-col :span="2">
                            <a-spin class="circle-cust">
                                <a-icon slot="indicator" type="rise" style="font-size: 24px" />
                            </a-spin>
                        </a-col>
                    </a-row>
                    <line-chart-multid :fields="visitFields"
                        :dataSource="visitInfo"></line-chart-multid> -->
                </a-card>
            </a-col>
        </a-row>
    </div>
</template>

<script>
import ChartCard from '@/components/ChartCard'
import ACol from 'ant-design-vue/es/grid/Col'
import ATooltip from 'ant-design-vue/es/tooltip/Tooltip'
import MiniArea from '@/components/chart/MiniArea'
import MiniBar from '@/components/chart/MiniBar'
import MiniProgress from '@/components/chart/MiniProgress'
import RankList from '@/components/chart/RankList'
import Bar from '@/components/chart/Bar'
import LineChartMultid from '@/components/chart/LineChartMultid'
import HeadInfo from '@/components/tools/HeadInfo.vue'

import Trend from '@/components/Trend'
import { getLoginfo, getVisitInfo } from '@/api/api'

import { httpAction, getAction, postAction } from '@/api/manage'

const rankList = []
for (let i = 0; i < 7; i++) {
    rankList.push({
        name: '白鹭岛 ' + (i + 1) + ' 号店',
        total: 1234.56 - i * 100,
    })
}
const barData = []
for (let i = 0; i < 12; i += 1) {
    barData.push({
        x: `${i + 1}月`,
        y: Math.floor(Math.random() * 1000) + 200,
    })
}
export default {
    name: 'IndexChart',
    components: {
        ATooltip,
        ACol,
        ChartCard,
        MiniArea,
        MiniBar,
        MiniProgress,
        RankList,
        Bar,
        Trend,
        LineChartMultid,
        HeadInfo,
    },
    data() {
        return {
            loading: true,
            center: null,
            rankList,
            barData,
            loginfo: {},
            visitFields: ['ip', 'visit'],
            visitInfo: [],
            indicator: <a-icon type="loading" style="font-size: 24px" spin />,
            queryParam: {
                startTime: undefined,
                endTime: undefined
            },
            url: {
                reportCard: "/tankerRegistration/tankerRegistration/reportCard",
            },
            qualifiedTotal: { total: 0, totalUnique: 0 },
            noPassTotal: { noPassTotal: 0, noPassUnique: 0 },
            unqualifiedTotal: { unqualifiedTotal: 0, unqualifiedUnique: 0 },
        }
    },
    created() {
        setTimeout(() => {
            this.loading = !this.loading
        }, 1000)
        this.initLogInfo()
    },
    mounted() {
        this.searchQuery()
    },
    methods: {
        searchQuery() {
            this.reportCard()
        },
        reportCard() {
            postAction(this.url.reportCard, this.queryParam).then((res) => {
                if (res.success) {
                    this.qualifiedTotal = res.result[0]
                    this.noPassTotal = res.result[1]
                    this.unqualifiedTotal = res.result[2]
                    this.$nextTick(() => {
                        this.showPie(res.result)
                    })
                }
            })
        },
        initLogInfo() {
            getLoginfo(null).then((res) => {
                if (res.success) {
                    Object.keys(res.result).forEach((key) => {
                        res.result[key] = res.result[key] + ''
                    })
                    this.loginfo = res.result
                }
            })
            getVisitInfo().then((res) => {
                if (res.success) {
                    this.visitInfo = res.result
                }
            })
        },
    },
}
</script>

<style lang="less" scoped>
.circle-cust {
    position: relative;
    top: 28px;
    left: -100%;
}
.extra-wrapper {
    line-height: 55px;
    padding-right: 24px;

    .extra-item {
        display: inline-block;
        margin-right: 24px;

        a {
            margin-left: 24px;
        }
    }
}

/* 首页访问量统计 */
.head-info {
    position: relative;
    text-align: left;
    padding: 0 32px 0 0;
    min-width: 125px;

    &.center {
        text-align: center;
        padding: 0 32px;
    }

    span {
        color: rgba(0, 0, 0, 0.45);
        display: inline-block;
        font-size: 0.95rem;
        line-height: 42px;
        margin-bottom: 4px;
    }
    p {
        line-height: 42px;
        margin: 0;
        a {
            font-weight: 600;
            font-size: 1rem;
        }
    }
}
</style>